/**
 * Packet Structure for Sanitas Server & Proxy
 */
package edu.ufl.cise.sanitas.types.comm;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.ObjectInputStream.GetField;

import edu.ufl.cise.sanitas.types.data.User;


/**
 * @deprecated
 * @author tan
 * @version 1.0.0
 */
public class SanitasPacket implements Serializable {

	private Object info; // packet information (user obj, feed obj)
	private boolean comp; // false for no-compress, true for compress
	private String type; // define the package type(feed, sync...)

	/**
	 * Define a package
	 * 
	 * @param comp
	 * @param type
	 * @param info
	 */
	SanitasPacket(boolean comp, String type, Object info) {
		this.comp = comp;
		this.type = type;
		this.info = info;
	}

	public boolean getComp() {
		return comp;
	}

	public String getTyp() {
		return type;
	}

	public Object getDetail() {
		return info;
	}

	public void setDetail(Object detail) {
		this.info = detail;
	}

	/**
	 * @param args
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	public static void main(String[] args) throws IOException,
			ClassNotFoundException {

		User u = new User(-1, "wzy", "google", "m", 20, 100, null);

		SanitasPacket sp = new SanitasPacket(false, "000", u);

		System.out.println(sp.comp);
		System.out.println(sp.type);
		System.out.println(sp.info.getClass());

		Object obj = sp.info;

		User u2 = (User) obj;

		System.out.println(u2.getName());

		String str = sp.type;

		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(str);
		oos.flush();
		oos.close();
		bos.close();

		byte[] data = bos.toByteArray();

		System.out.println(data.length);

		String u3 = (String) new ObjectInputStream(new ByteArrayInputStream(
				data)).readObject();

		System.out.println(u3);
	}
}
